﻿#region Using directives

using System;
using System.Collections;
using System.Collections.Specialized;


using System.Web.Configuration;
using System.Data;
using System.Data.Common;
using System.Configuration.Provider;

using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

using InvoiceChecking.Entities;
using InvoiceChecking.Data;
using InvoiceChecking.Data.Bases;

#endregion

namespace InvoiceChecking.Data.SqlClient
{
	/// <summary>
	/// This class is the Sql implementation of the NetTiersProvider.
	/// </summary>
	public sealed class SqlNetTiersProvider : InvoiceChecking.Data.Bases.NetTiersProvider
	{
		private static object syncRoot = new Object();
		private string _applicationName;
        private string _connectionString;
        private bool _useStoredProcedure;
        string _providerInvariantName;
		
		/// <summary>
		/// Initializes a new instance of the <see cref="SqlNetTiersProvider"/> class.
		///</summary>
		public SqlNetTiersProvider()
		{	
		}		
		
		/// <summary>
        /// Initializes the provider.
        /// </summary>
        /// <param name="name">The friendly name of the provider.</param>
        /// <param name="config">A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.</param>
        /// <exception cref="T:System.ArgumentNullException">The name of the provider is null.</exception>
        /// <exception cref="T:System.InvalidOperationException">An attempt is made to call <see cref="M:System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection)"></see> on a provider after the provider has already been initialized.</exception>
        /// <exception cref="T:System.ArgumentException">The name of the provider has a length of zero.</exception>
		public override void Initialize(string name, NameValueCollection config)
        {
            // Verify that config isn't null
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            // Assign the provider a default name if it doesn't have one
            if (String.IsNullOrEmpty(name))
            {
                name = "SqlNetTiersProvider";
            }

            // Add a default "description" attribute to config if the
            // attribute doesn't exist or is empty
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", "NetTiers Sql provider");
            }

            // Call the base class's Initialize method
            base.Initialize(name, config);

            // Initialize _applicationName
            _applicationName = config["applicationName"];

            if (string.IsNullOrEmpty(_applicationName))
            {
                _applicationName = "/";
            }
            config.Remove("applicationName");


            #region "Initialize UseStoredProcedure"
            string storedProcedure  = config["useStoredProcedure"];
           	if (string.IsNullOrEmpty(storedProcedure))
            {
                throw new ProviderException("Empty or missing useStoredProcedure");
            }
            this._useStoredProcedure = Convert.ToBoolean(config["useStoredProcedure"]);
            config.Remove("useStoredProcedure");
            #endregion

			#region ConnectionString

			// Initialize _connectionString
			_connectionString = config["connectionString"];
			config.Remove("connectionString");

			string connect = config["connectionStringName"];
			config.Remove("connectionStringName");

			if ( String.IsNullOrEmpty(_connectionString) )
			{
				if ( String.IsNullOrEmpty(connect) )
				{
					throw new ProviderException("Empty or missing connectionStringName");
				}

				if ( DataRepository.ConnectionStrings[connect] == null )
				{
					throw new ProviderException("Missing connection string");
				}

				_connectionString = DataRepository.ConnectionStrings[connect].ConnectionString;
			}

            if ( String.IsNullOrEmpty(_connectionString) )
            {
                throw new ProviderException("Empty connection string");
			}

			#endregion
            
             #region "_providerInvariantName"

            // initialize _providerInvariantName
            this._providerInvariantName = config["providerInvariantName"];

            if (String.IsNullOrEmpty(_providerInvariantName))
            {
                throw new ProviderException("Empty or missing providerInvariantName");
            }
            config.Remove("providerInvariantName");

            #endregion

        }
		
		/// <summary>
		/// Creates a new <see cref="TransactionManager"/> instance from the current datasource.
		/// </summary>
		/// <returns></returns>
		public override TransactionManager CreateTransaction()
		{
			return new TransactionManager(this._connectionString);
		}
		
		/// <summary>
		/// Gets a value indicating whether to use stored procedure or not.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this repository use stored procedures; otherwise, <c>false</c>.
		/// </value>
		public bool UseStoredProcedure
		{
			get {return this._useStoredProcedure;}
			set {this._useStoredProcedure = value;}
		}
		
		 /// <summary>
        /// Gets or sets the connection string.
        /// </summary>
        /// <value>The connection string.</value>
		public string ConnectionString
		{
			get {return this._connectionString;}
			set {this._connectionString = value;}
		}
		
		/// <summary>
	    /// Gets or sets the invariant provider name listed in the DbProviderFactories machine.config section.
	    /// </summary>
	    /// <value>The name of the provider invariant.</value>
	    public string ProviderInvariantName
	    {
	        get { return this._providerInvariantName; }
	        set { this._providerInvariantName = value; }
	    }		
		
		///<summary>
		/// Indicates if the current <see cref="NetTiersProvider"/> implementation supports Transacton.
		///</summary>
		public override bool IsTransactionSupported
		{
			get
			{
				return true;
			}
		}

		
		#region "AbAccountCodeProvider"
			
		private SqlAbAccountCodeProvider innerSqlAbAccountCodeProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="AbAccountCode"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override AbAccountCodeProviderBase AbAccountCodeProvider
		{
			get
			{
				if (innerSqlAbAccountCodeProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlAbAccountCodeProvider == null)
						{
							this.innerSqlAbAccountCodeProvider = new SqlAbAccountCodeProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlAbAccountCodeProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlAbAccountCodeProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlAbAccountCodeProvider SqlAbAccountCodeProvider
		{
			get {return AbAccountCodeProvider as SqlAbAccountCodeProvider;}
		}
		
		#endregion
		
		
		#region "PaymentAccountProvider"
			
		private SqlPaymentAccountProvider innerSqlPaymentAccountProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="PaymentAccount"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override PaymentAccountProviderBase PaymentAccountProvider
		{
			get
			{
				if (innerSqlPaymentAccountProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlPaymentAccountProvider == null)
						{
							this.innerSqlPaymentAccountProvider = new SqlPaymentAccountProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlPaymentAccountProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlPaymentAccountProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlPaymentAccountProvider SqlPaymentAccountProvider
		{
			get {return PaymentAccountProvider as SqlPaymentAccountProvider;}
		}
		
		#endregion
		
		
		#region "PaymentTypeProvider"
			
		private SqlPaymentTypeProvider innerSqlPaymentTypeProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="PaymentType"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override PaymentTypeProviderBase PaymentTypeProvider
		{
			get
			{
				if (innerSqlPaymentTypeProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlPaymentTypeProvider == null)
						{
							this.innerSqlPaymentTypeProvider = new SqlPaymentTypeProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlPaymentTypeProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlPaymentTypeProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlPaymentTypeProvider SqlPaymentTypeProvider
		{
			get {return PaymentTypeProvider as SqlPaymentTypeProvider;}
		}
		
		#endregion
		
		
		#region "PaymentProvider"
			
		private SqlPaymentProvider innerSqlPaymentProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Payment"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override PaymentProviderBase PaymentProvider
		{
			get
			{
				if (innerSqlPaymentProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlPaymentProvider == null)
						{
							this.innerSqlPaymentProvider = new SqlPaymentProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlPaymentProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlPaymentProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlPaymentProvider SqlPaymentProvider
		{
			get {return PaymentProvider as SqlPaymentProvider;}
		}
		
		#endregion
		
		
		#region "SunReferenceProvider"
			
		private SqlSunReferenceProvider innerSqlSunReferenceProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="SunReference"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override SunReferenceProviderBase SunReferenceProvider
		{
			get
			{
				if (innerSqlSunReferenceProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlSunReferenceProvider == null)
						{
							this.innerSqlSunReferenceProvider = new SqlSunReferenceProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlSunReferenceProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlSunReferenceProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlSunReferenceProvider SqlSunReferenceProvider
		{
			get {return SunReferenceProvider as SqlSunReferenceProvider;}
		}
		
		#endregion
		
		
		#region "VoidReasonProvider"
			
		private SqlVoidReasonProvider innerSqlVoidReasonProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="VoidReason"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override VoidReasonProviderBase VoidReasonProvider
		{
			get
			{
				if (innerSqlVoidReasonProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlVoidReasonProvider == null)
						{
							this.innerSqlVoidReasonProvider = new SqlVoidReasonProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlVoidReasonProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlVoidReasonProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlVoidReasonProvider SqlVoidReasonProvider
		{
			get {return VoidReasonProvider as SqlVoidReasonProvider;}
		}
		
		#endregion
		
		
		#region "NewRevenueVnProvider"
			
		private SqlNewRevenueVnProvider innerSqlNewRevenueVnProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="NewRevenueVn"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override NewRevenueVnProviderBase NewRevenueVnProvider
		{
			get
			{
				if (innerSqlNewRevenueVnProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlNewRevenueVnProvider == null)
						{
							this.innerSqlNewRevenueVnProvider = new SqlNewRevenueVnProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlNewRevenueVnProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlNewRevenueVnProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlNewRevenueVnProvider SqlNewRevenueVnProvider
		{
			get {return NewRevenueVnProvider as SqlNewRevenueVnProvider;}
		}
		
		#endregion
		
		
		#region "PaymentDetailProvider"
			
		private SqlPaymentDetailProvider innerSqlPaymentDetailProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="PaymentDetail"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override PaymentDetailProviderBase PaymentDetailProvider
		{
			get
			{
				if (innerSqlPaymentDetailProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlPaymentDetailProvider == null)
						{
							this.innerSqlPaymentDetailProvider = new SqlPaymentDetailProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlPaymentDetailProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlPaymentDetailProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlPaymentDetailProvider SqlPaymentDetailProvider
		{
			get {return PaymentDetailProvider as SqlPaymentDetailProvider;}
		}
		
		#endregion
		
		
		#region "NewRevenueProvider"
			
		private SqlNewRevenueProvider innerSqlNewRevenueProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="NewRevenue"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override NewRevenueProviderBase NewRevenueProvider
		{
			get
			{
				if (innerSqlNewRevenueProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlNewRevenueProvider == null)
						{
							this.innerSqlNewRevenueProvider = new SqlNewRevenueProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlNewRevenueProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlNewRevenueProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlNewRevenueProvider SqlNewRevenueProvider
		{
			get {return NewRevenueProvider as SqlNewRevenueProvider;}
		}
		
		#endregion
		
		
		#region "CreditCardProvider"
			
		private SqlCreditCardProvider innerSqlCreditCardProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="CreditCard"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override CreditCardProviderBase CreditCardProvider
		{
			get
			{
				if (innerSqlCreditCardProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlCreditCardProvider == null)
						{
							this.innerSqlCreditCardProvider = new SqlCreditCardProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlCreditCardProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlCreditCardProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlCreditCardProvider SqlCreditCardProvider
		{
			get {return CreditCardProvider as SqlCreditCardProvider;}
		}
		
		#endregion
		
		
		#region "JournalVoucherTypeProvider"
			
		private SqlJournalVoucherTypeProvider innerSqlJournalVoucherTypeProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="JournalVoucherType"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override JournalVoucherTypeProviderBase JournalVoucherTypeProvider
		{
			get
			{
				if (innerSqlJournalVoucherTypeProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlJournalVoucherTypeProvider == null)
						{
							this.innerSqlJournalVoucherTypeProvider = new SqlJournalVoucherTypeProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlJournalVoucherTypeProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlJournalVoucherTypeProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlJournalVoucherTypeProvider SqlJournalVoucherTypeProvider
		{
			get {return JournalVoucherTypeProvider as SqlJournalVoucherTypeProvider;}
		}
		
		#endregion
		
		
		#region "DailyTransProvider"
			
		private SqlDailyTransProvider innerSqlDailyTransProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="DailyTrans"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override DailyTransProviderBase DailyTransProvider
		{
			get
			{
				if (innerSqlDailyTransProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlDailyTransProvider == null)
						{
							this.innerSqlDailyTransProvider = new SqlDailyTransProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlDailyTransProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlDailyTransProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlDailyTransProvider SqlDailyTransProvider
		{
			get {return DailyTransProvider as SqlDailyTransProvider;}
		}
		
		#endregion
		
		
		#region "CheckInvoiceProvider"
			
		private SqlCheckInvoiceProvider innerSqlCheckInvoiceProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="CheckInvoice"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override CheckInvoiceProviderBase CheckInvoiceProvider
		{
			get
			{
				if (innerSqlCheckInvoiceProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlCheckInvoiceProvider == null)
						{
							this.innerSqlCheckInvoiceProvider = new SqlCheckInvoiceProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlCheckInvoiceProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlCheckInvoiceProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlCheckInvoiceProvider SqlCheckInvoiceProvider
		{
			get {return CheckInvoiceProvider as SqlCheckInvoiceProvider;}
		}
		
		#endregion
		
		
		#region "JournalVoucherProvider"
			
		private SqlJournalVoucherProvider innerSqlJournalVoucherProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="JournalVoucher"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override JournalVoucherProviderBase JournalVoucherProvider
		{
			get
			{
				if (innerSqlJournalVoucherProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlJournalVoucherProvider == null)
						{
							this.innerSqlJournalVoucherProvider = new SqlJournalVoucherProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlJournalVoucherProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlJournalVoucherProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlJournalVoucherProvider SqlJournalVoucherProvider
		{
			get {return JournalVoucherProvider as SqlJournalVoucherProvider;}
		}
		
		#endregion
		
		
		#region "InvoiceCheckingUserProvider"
			
		private SqlInvoiceCheckingUserProvider innerSqlInvoiceCheckingUserProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="InvoiceCheckingUser"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override InvoiceCheckingUserProviderBase InvoiceCheckingUserProvider
		{
			get
			{
				if (innerSqlInvoiceCheckingUserProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlInvoiceCheckingUserProvider == null)
						{
							this.innerSqlInvoiceCheckingUserProvider = new SqlInvoiceCheckingUserProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlInvoiceCheckingUserProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlInvoiceCheckingUserProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlInvoiceCheckingUserProvider SqlInvoiceCheckingUserProvider
		{
			get {return InvoiceCheckingUserProvider as SqlInvoiceCheckingUserProvider;}
		}
		
		#endregion
		
		
		#region "TcodeProvider"
			
		private SqlTcodeProvider innerSqlTcodeProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Tcode"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override TcodeProviderBase TcodeProvider
		{
			get
			{
				if (innerSqlTcodeProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlTcodeProvider == null)
						{
							this.innerSqlTcodeProvider = new SqlTcodeProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlTcodeProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlTcodeProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlTcodeProvider SqlTcodeProvider
		{
			get {return TcodeProvider as SqlTcodeProvider;}
		}
		
		#endregion
		
		
		#region "JournalDetailsProvider"
			
		private SqlJournalDetailsProvider innerSqlJournalDetailsProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="JournalDetails"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override JournalDetailsProviderBase JournalDetailsProvider
		{
			get
			{
				if (innerSqlJournalDetailsProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlJournalDetailsProvider == null)
						{
							this.innerSqlJournalDetailsProvider = new SqlJournalDetailsProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlJournalDetailsProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlJournalDetailsProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlJournalDetailsProvider SqlJournalDetailsProvider
		{
			get {return JournalDetailsProvider as SqlJournalDetailsProvider;}
		}
		
		#endregion
		
		
		
		#region "AllInvoiceProvider"
		
		private SqlAllInvoiceProvider innerSqlAllInvoiceProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="AllInvoice"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override AllInvoiceProviderBase AllInvoiceProvider
		{
			get
			{
				if (innerSqlAllInvoiceProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlAllInvoiceProvider == null)
						{
							this.innerSqlAllInvoiceProvider = new SqlAllInvoiceProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlAllInvoiceProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlAllInvoiceProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlAllInvoiceProvider SqlAllInvoiceProvider
		{
			get {return AllInvoiceProvider as SqlAllInvoiceProvider;}
		}
		
		#endregion
		
		
		#region "SunAccountCodeProvider"
		
		private SqlSunAccountCodeProvider innerSqlSunAccountCodeProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="SunAccountCode"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override SunAccountCodeProviderBase SunAccountCodeProvider
		{
			get
			{
				if (innerSqlSunAccountCodeProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlSunAccountCodeProvider == null)
						{
							this.innerSqlSunAccountCodeProvider = new SqlSunAccountCodeProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlSunAccountCodeProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlSunAccountCodeProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlSunAccountCodeProvider SqlSunAccountCodeProvider
		{
			get {return SunAccountCodeProvider as SqlSunAccountCodeProvider;}
		}
		
		#endregion
		
		
		#region "SunInvoiceProvider"
		
		private SqlSunInvoiceProvider innerSqlSunInvoiceProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="SunInvoice"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override SunInvoiceProviderBase SunInvoiceProvider
		{
			get
			{
				if (innerSqlSunInvoiceProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlSunInvoiceProvider == null)
						{
							this.innerSqlSunInvoiceProvider = new SqlSunInvoiceProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlSunInvoiceProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlSunInvoiceProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlSunInvoiceProvider SqlSunInvoiceProvider
		{
			get {return SunInvoiceProvider as SqlSunInvoiceProvider;}
		}
		
		#endregion
		
		
		#region "SunJournalVoucherProvider"
		
		private SqlSunJournalVoucherProvider innerSqlSunJournalVoucherProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="SunJournalVoucher"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override SunJournalVoucherProviderBase SunJournalVoucherProvider
		{
			get
			{
				if (innerSqlSunJournalVoucherProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlSunJournalVoucherProvider == null)
						{
							this.innerSqlSunJournalVoucherProvider = new SqlSunJournalVoucherProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlSunJournalVoucherProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlSunJournalVoucherProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlSunJournalVoucherProvider SqlSunJournalVoucherProvider
		{
			get {return SunJournalVoucherProvider as SqlSunJournalVoucherProvider;}
		}
		
		#endregion
		
		
		#region "SunPaymentVoucherProvider"
		
		private SqlSunPaymentVoucherProvider innerSqlSunPaymentVoucherProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="SunPaymentVoucher"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override SunPaymentVoucherProviderBase SunPaymentVoucherProvider
		{
			get
			{
				if (innerSqlSunPaymentVoucherProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlSunPaymentVoucherProvider == null)
						{
							this.innerSqlSunPaymentVoucherProvider = new SqlSunPaymentVoucherProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlSunPaymentVoucherProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlSunPaymentVoucherProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlSunPaymentVoucherProvider SqlSunPaymentVoucherProvider
		{
			get {return SunPaymentVoucherProvider as SqlSunPaymentVoucherProvider;}
		}
		
		#endregion
		
		
		#region "SunReportPrintingProvider"
		
		private SqlSunReportPrintingProvider innerSqlSunReportPrintingProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="SunReportPrinting"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override SunReportPrintingProviderBase SunReportPrintingProvider
		{
			get
			{
				if (innerSqlSunReportPrintingProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlSunReportPrintingProvider == null)
						{
							this.innerSqlSunReportPrintingProvider = new SqlSunReportPrintingProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlSunReportPrintingProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlSunReportPrintingProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlSunReportPrintingProvider SqlSunReportPrintingProvider
		{
			get {return SunReportPrintingProvider as SqlSunReportPrintingProvider;}
		}
		
		#endregion
		
		
		#region "VrProcPharRevProvider"
		
		private SqlVrProcPharRevProvider innerSqlVrProcPharRevProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="VrProcPharRev"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override VrProcPharRevProviderBase VrProcPharRevProvider
		{
			get
			{
				if (innerSqlVrProcPharRevProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlVrProcPharRevProvider == null)
						{
							this.innerSqlVrProcPharRevProvider = new SqlVrProcPharRevProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlVrProcPharRevProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlVrProcPharRevProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlVrProcPharRevProvider SqlVrProcPharRevProvider
		{
			get {return VrProcPharRevProvider as SqlVrProcPharRevProvider;}
		}
		
		#endregion
		
		
		#region "General data access methods"

		#region "ExecuteNonQuery"
		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		public override void ExecuteNonQuery(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			database.ExecuteNonQuery(commandWrapper);	
			
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		public override void ExecuteNonQuery(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			database.ExecuteNonQuery(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(commandType, commandText);	
		}
		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteNonQuery(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteDataReader"
		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteReader(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteReader(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteReader(commandWrapper);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteReader(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteReader(commandType, commandText);	
		}
		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteReader(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteDataSet"
		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteDataSet(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteDataSet(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteDataSet(commandWrapper);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteDataSet(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteDataSet(commandType, commandText);	
		}
		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteDataSet(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteScalar"
		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override object ExecuteScalar(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteScalar(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteScalar(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override object ExecuteScalar(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteScalar(commandWrapper);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteScalar(commandWrapper, transactionManager.TransactionObject);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override object ExecuteScalar(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteScalar(commandType, commandText);	
		}
		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteScalar(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#endregion


	}
}
